<?php
namespace app\helper;

use GuzzleHttp\Client;

/**
 *
 */
class Http
{
    private $client;
    /**
     * 一个值
     *
     * @param array $conf
     * @return void
     */
    public function __construct(array $conf = [])
    {
        $this->client = new Client([
            // Base URI is used with relative requests
            'base_uri' => 'http://httpbin.org',
            // You can set any number of default request options.
            'timeout'  => 2.0,
        ]);
    }
    public function get(string $path = '', array $data = []){
        $response = $this->client->get($path, ['query' => $data]);
        return $this->client($response);
    }
    public function post(string $path = '', array $data = []){
        $response = $this->client->post($path, ['json' => $data]);
        return $this->client($response);
    }
    public function put(string $path = '', array $data = []){
        $response = $this->client->put($path, ['json' => $data]);
        return $this->client($response);
    }
    public function patch(string $path = '', array $data = []){
        $response = $this->client->patch($path, ['json' => $data]);
        return $this->client($response);
    }
    public function delete(string $path = ''){
        $response = $this->client->delete($path);
        return $this->client($response);
    }
    private function handle(object $response){
        if($response->getStatusCode() === 200){
            $body = json_decode($response->getBody());
            return $body;
        }
    }
}
